package com.sh.redis.suanfa;

import com.sh.entity.dto.TreeNode;

public class TreeQianxu {

    public static void main(String[] args) {
        TreeNode node7 = new TreeNode(7,null,null);
        TreeNode node6 = new TreeNode(6,node7,null);
        TreeNode node5 = new TreeNode(5,null,null);
        TreeNode node4 = new TreeNode(4,null,null);
        TreeNode node3 = new TreeNode(3,node6,null);
        TreeNode node2 = new TreeNode(2,node4,node5);
        TreeNode node1 = new TreeNode(1,node2,node3);
        System.out.println("前序");
        qianxu(node1);
        System.out.println();
        System.out.println("中序");
        zhongxu(node1);
        System.out.println();
        System.out.println("后序");
        houxu(node1);
        System.out.println();
    }


    public static void qianxu(TreeNode root){
        if(root == null){
            return ;
        }
        System.out.print(root.getValue());
        qianxu(root.getLeft());
        qianxu(root.getRight());
    }

    public static void zhongxu(TreeNode root){
        if(root == null){
            return ;
        }
        zhongxu(root.getLeft());
        System.out.print(root.getValue());
        zhongxu(root.getRight());
    }

    public static void houxu(TreeNode root){
        if(root == null){
            return ;
        }
        houxu(root.getLeft());
        houxu(root.getRight());
        System.out.print(root.getValue());
    }


}
